﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DelegateTest1
{
    public delegate void PrintString(string s);
    public delegate void Print1<T>(T s);
    public delegate T Print2<T>(T s);
    class Program
    {

        static void Main(string[] args)
        {
            PrintString ps1 = new PrintString(WriteToFile);
            PrintString ps2 = new PrintString(WriteToScreen);

            SendString(ps1);
            SendString(ps2);



            

            Console.ReadKey();
        }



        public static void WriteToScreen(string s)
        {
            Console.WriteLine("The string is = " + s);
        }

        public static void WriteToFile(string s)
        {
            FileStream stream = new FileStream("H:\\zy\\message.txt", FileMode.Append, FileAccess.Write);
            StreamWriter sw = new StreamWriter(stream);
            sw.WriteLine(s);
            sw.Flush();
            sw.Close();
            stream.Close();
        }

        public static void SendString(PrintString ps)
        {
            ps("Hello everyone! I'm back!");
        }
    }
}
